// src/Service/book-update.js

import request from "@/util/request";

/**
 * 上传 SQL 文件到后端 /booksupdate 接口
 * @param {File} file - 用户选择的 .sql 文件
 * @returns {Promise<any>} 接口返回的数据
 */
async function uploadSQLFile(file) {
    if (!file) {
        throw new Error("未选择文件");
    }

    const formData = new FormData();
    formData.append("file", file);

    try {
        const response = await request.put("/system/booksupdate", formData, {
            headers: {
                "Content-Type": "multipart/form-data",
                // Authorization: `Bearer ${localStorage.getItem('token')}` // 添加这一行
            }
        });

        return response;
    } catch (error) {
        console.error("SQL 文件上传失败:", error);
        throw error;
    }
}

export { uploadSQLFile };